from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from .ser import *
# Create your views here.

class CateM(APIView):
    def get(self,request):
        se=Cate.objects.all()
        ser = Cateser(se,many=True)
        return Response({'code':200,'list':ser.data})

from django.core.paginator import Paginator
class BookM(APIView):
    def get(self,request):
        sy = Books.objects.all()
        cpage = request.GET.get('p')
        p = Paginator(sy,2)
        re = p.page(cpage)
        ser = Bookser(re,many=True)
        return Response({'code': 200, 'list': ser.data, "tpage": p.num_pages})

class Bookmanage(APIView):
    def get(self,request):
        name = request.GET.get('name')
        se = Books.objects.filter(name=name).all()
        ser1 = Bookser(se,many=True)
        return Response({'code':200,'list':ser1.data})
